/* 

Replication File for Null Result of Nudges on Citizenship*
Author: Michael Hotard
Date: March 9, 2020

This script runs the replication code for the Null Results Report Nudges for Citizenship Fee. 

It requires the replication dataset called "nnyFeeWaiverNullReplicationFile.dta."

The replication dataset bins the variables household income, years on green card, and age into quartiles. Because of this, the exact numbers will not match those reported in the null results report for 
regressions that are run with those covariates. 


*/


set more off

**** define data file location and output location


global fileLocation = "/Users/alaalrababah/Dropbox (IPL)/Refugees_Jordan/Changing Attitudes Project/null_effects/replication_code/"
global outputFolder = "/Users/alaalrababah/Dropbox (IPL)/Refugees_Jordan/Changing Attitudes Project/null_effects/replication_code/tables"


**** loading in the data

cd "$fileLocation"
use nny_data, clear

**** setting the output location

cd "$outputFolder"


**** setting covariates for models

global nudge_covars = "treat_Enhanced treat_Invite"
global covars = "hhinc_cap_Q yrs_greencard_Q age_Q gender_f origin_DR origin_Ecuador origin_Jamaica marital_married marital_single educ_HS educ_somecollege educ_BA lang_Span"



**** Table 1 - Balance checks

mlogit feewaivermessage_f $covars , robust base(0)


eststo clear
eststo: mlogit feewaivermessage_f $covars , robust base(0)
test $covars

estadd scalar chi = r(chi2)
estadd scalar pp = r(p)


esttab * using tableB1.tex, unstack varlabels(_cons Constant)   label pr2 scalars("chi Chi-Square" "pp P-value") ///
 cells(b(fmt(%9.3f)) se(par)) nonumbers noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
  mgroups("Treatment Groups:", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
 title(Balance Checks for Nudge Study (All Participants) \label{balcheckNudge1}) eqlabels("Enhanced" "Invitation") ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{6.2in}}{\scriptsize ///
 \emph{Note}: Multinomial logit regression coefficients shown with robust standard errors in parentheses. The reference category is participants in the control group that received no additional nudge. ///
 Chi-Square and P-value in the bottom rows are from an omnibus Chi-Square test against the null that all slope coefficients are jointly equal to zero. ///
 This model is based on the sample of all participants. One participant did not report their gender, which is why analyses that include Female have only 748 observations.} ///
 \end{tabular} ///
 \end{table} ///
 )
 
 

 **** Table 2 - Balance checks for responders
 
mlogit feewaivermessage_f $covars , robust base(0) , if submitted!=.
test $covars
 
eststo clear
eststo: mlogit feewaivermessage_f $covars , robust base(0) , if submitted!=.
test $covars
estadd scalar pp = r(p)
estadd scalar chi = r(chi2)


esttab * using tableB2.tex, unstack varlabels(_cons Constant)  label pr2 scalar("chi Chi-Square" "pp P-value") ///
 cells(b(fmt(%9.3f)) se(par)) nonumbers noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
  mgroups("Treatment Groups:", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
 title(Balance Checks for Nudge Study (Responders to follow-up survey) \label{balcheckNudge2}) eqlabels("Enhanced" "Invitation") ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{6.2in}}{\scriptsize ///
 \emph{Note}: Multinomial logit regression coefficients shown with robust standard errors in parentheses. The reference category are participants in the control group that received no additional nudge. ///
 Chi-Square and P-value in the bottom rows are from an omnibus Chi-Square test against the null that all slope coefficients are jointly equal to zero. ///
 This model is based on the samples of all participants who responded to the follow-up survey.} ///
 \end{tabular} ///
 \end{table} ///
 )
 

**** Table 3 - Survey response checks
 

 
* fee waiver group

reg replied $nudge_covars, robust
reg replied $nudge_covars $covars, robust

eststo clear

*model 1
eststo: reg replied $nudge_covars, robust
estadd local covars "No"
test $nudge_covars
estadd scalar pp=r(p)
estadd scalar ff = r(F)


*model 2
eststo: reg replied $nudge_covars $covars, robust
estadd local covars "Yes"
test $nudge_covars
estadd scalar pp=r(p)
estadd scalar ff = r(F)



esttab * using tableB3.tex, varlabels(_cons Constant) label prehead( ///
\begin{table}[htbp]\centering \footnotesize ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Survey Response Checks for Fee Waiver Group \label{replyNudge}} ///
\begin{tabular}{l*{2}{c}} ///
\hline \hline ) ///
 cells(b(fmt(%9.3f)) se(par)) noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
 mgroups("Responded to Survey", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) stats(covars N r2_a ff pp,fmt(2 "" 0 "" 3) labels("Covariates" "Observations" "Adusted R$^2$" "F-value" "P-value"))  ///
 title(Survey Response Checks for Nudge Group \label{replyNudge}) ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{4.2in}}{\scriptsize ///
 \emph{Note}: Regression coefficients shown with robust standard errors in parentheses. ///
 Model 1 regresses whether a participant responded to the survey on the nudge group assignment indicators (the control group that received no additional nudge is the reference category). ///
 Model 2 adds covariates. ///
 The F-test is against the null that the regression coeffificients on the nudge group assignment indicators are jointly equal to null. } ///
 \end{tabular} ///
 \end{table} ///
 )
 
 
**** Table 4- Effects (main estimate)


 
 
* fee waiver group

reg submitted $nudge_covars, robust
reg submitted $nudge_covars $covars, robust

eststo clear

*model 1 (no covariates)
eststo: reg submitted $nudge_covars, robust
estadd local covars "No"

* save stats for R figure
capture matrix drop res

* control mean
lincom _cons*100
mat res1 = r(estimate) , r(se)
mat rownames res1 = "Control"
mat res = nullmat(res) \ res1

* treatment means
foreach x of global nudge_covars {
lincom (_cons + `x')*100
mat res1 = r(estimate) , r(se)
mat rownames res1 = "`x'"
mat res = nullmat(res) \ res1
matlist res
}




*model 2 (covariates adjusted)
eststo: reg submitted $nudge_covars $covars, robust
estadd local covars "Yes"

esttab * using tableB4.tex, varlabels(_cons Constant) label prehead( ///
\begin{table}[htbp]\centering \footnotesize ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Intention-to-treat Effect Estimates for Nudge Study \label{effectsNudge}} ///
\begin{tabular}{l*{2}{c}} ///
\hline \hline ) //////
 cells(b(fmt(%9.3f)) se(par)) noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
 mgroups("Applied for Naturalization", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) stats(covars N,fmt(2 "" 0) label("Covariates" "Observations"))  ///
 title(Intention-to-treat Effect Estimates for Nudge Study \label{effectsNudge}) ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{4.2in}}{\scriptsize ///
 \emph{Note}: Regression coefficients shown with robust standard errors in parentheses. ///
 Models 1 and 2 regress the outcome of whether someone submitted their citizenship applicatoin on indicators for whether participants were assigned to the various nudge groups (the control group that received no additional nudge is the reference category). ///
 } ///
 \end{tabular} ///
 \end{table} ///
 )
 
 
* treatment effects - output for R file to create figure
foreach x of global nudge_covars {
lincom `x'*100
mat res1 = r(estimate) , r(se)
mat rownames res1 = "delta `x'"
mat res = nullmat(res) \ res1
matlist res
} 



matrix colnames res = "pe" "se"
mat2txt, matrix(res) saving("nudgeeffects.txt") replace






***** Table 5 - efect on paying the fee

reg usefw $nudge_covars, robust, if submitted == 1
reg usefw $nudge_covars $covars, robust, if submitted == 1

eststo clear

*model 1 (no covariates)
eststo: reg usefw $nudge_covars, robust, if submitted == 1
estadd local covars "No"

*model 2 (covariates adjusted)
eststo: reg usefw $nudge_covars $covars, robust, if submitted == 1
estadd local covars "Yes"

esttab * using tableB5.tex, varlabels(_cons Constant) label prehead( ///
\begin{table}[htbp]\centering \footnotesize ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Intention-to-treat Effect Estimates for Fee Paid \label{usefw}} ///
\begin{tabular}{l*{2}{c}} ///
\hline \hline ) //////
 cells(b(fmt(%9.3f)) se(par)) noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
 mgroups("Paid Fee for Naturalization if Applied", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) stats(covars N,fmt(2 "" 0) label("Covariates" "Observations"))  ///
 title(Intention-to-treat Effect Estimates for Nudge Study \label{usefw}) ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{4.2in}}{\scriptsize ///
 \emph{Note}: Regression coefficients shown with robust standard errors in parentheses. ///
 Models 1 and 2 regress the outcome of whether someone paid to submit their citizenship application on indicators for whether participants were assigned to the various nudge groups (the control group that received no additional nudge is the reference category). ///
 } ///
 \end{tabular} ///
 \end{table} ///
 )
 

 
 
**** Table 6 - Effect on attending CUNY event 

reg cunyevent_f $nudge_covars, robust
reg cunyevent_f $nudge_covars $covars, robust

eststo clear

*model 1 (no covariates)
eststo: reg cunyevent_f $nudge_covars, robust
estadd local covars "No"


*model 2 (covariates adjusted)
eststo: reg cunyevent_f $nudge_covars $covars, robust
estadd local covars "Yes"

esttab * using tableB6.tex, varlabels(_cons Constant) label prehead( ///
\begin{table}[htbp]\centering \footnotesize ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Citizenship Workshop Attendance\label{cunyVisit}} ///
\begin{tabular}{l*{2}{c}} ///
\hline \hline ) //////
 cells(b(fmt(%9.3f)) se(par)) noomitted  nomtitle collabels(none) nobaselevels  varwidth(50) replace ///
 mgroups("Attended Specific Citizenship Workshop", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) stats(covars N,fmt(2 "" 0) label("Covariates" "Observations"))  ///
 title(Intention-to-treat Effect Estimates for Nudge Study \label{cunyVisit}) ///
 postfoot( ///
 \hline  ///
 \multicolumn{3}{p{4.2in}}{\scriptsize ///
 \emph{Note}: Regression coefficients shown with robust standard errors in parentheses. ///
 Models 1 and 2 regress the outcome of whether someone attended a specific citizenship workshop on indicators for whether participants were assigned to the various nudge groups (the control group that received no additional nudge is the reference category). ///
 } ///
 \end{tabular} ///
 \end{table} ///
 )
 
 
